<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据展示页面</title>
    <style>
        /* 基础样式重置 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Microsoft YaHei', sans-serif;
        }

        body {
            background-color: #f5f7fa;
            color: #333;
            line-height: 1.6;
            padding: 20px;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
        }

        /* 标题样式 */
        .page-title {
            text-align: center;
            margin-bottom: 30px;
            color: #2c3e50;
            position: relative;
        }

        .page-title:after {
            content: '';
            display: block;
            width: 100px;
            height: 3px;
            background: linear-gradient(to right, #3498db, #2980b9);
            margin: 10px auto 0;
            border-radius: 3px;
        }

        /* 数据展示容器 - 修改为flex布局实现居中 */
        .data-container {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 20px;
        }

        /* 数据卡片样式 */
        .data-card {
            background: white;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            position: relative;
            overflow: hidden;
            width: 300px; /* 设置固定宽度 */
        }

        .data-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
        }

        .data-card:before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 5px;
            height: 100%;
            background: linear-gradient(to bottom, #3498db, #2980b9);
            opacity: 0.8;
        }

        .card-header {
            padding: 15px 20px;
            background-color: #f8f9fa;
            border-bottom: 1px solid #e9ecef;
        }

        .card-title {
            font-size: 16px;
            font-weight: 600;
            color: #2c3e50;
        }

        .card-body {
            padding: 20px;
        }

        .data-list {
            list-style: none;
        }

        .data-list li {
            padding: 10px 0;
            border-bottom: 1px dashed #e9ecef;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .data-list li:last-child {
            border-bottom: none;
        }

        .data-value {
            font-size: 14px;
            color: #333;
        }

        .data-index {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 24px;
            height: 24px;
            background-color: #e3f2fd;
            color: #1976d2;
            border-radius: 50%;
            font-size: 12px;
            font-weight: bold;
            margin-right: 10px;
        }

        /* 空数据提示 */
        .empty-data {
            text-align: center;
            padding: 50px 20px;
            color: #757575;
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
        }

        .empty-data i {
            font-size: 48px;
            margin-bottom: 15px;
            color: #bdbdbd;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .page-title {
                font-size: 24px;
            }

            .data-card {
                width: 100%;
            }
        }
    </style>
</head>
<body>
<div class="container">
    <h1 class="page-title">好友列表展示</h1>

    <div class="data-container">
        <!-- 数据卡片 1 - 基础列表展示 -->
        <div class="data-card">
            <div class="card-header">
                <h3 class="card-title">我的好友列表</h3>
            </div>
            <div class="card-body">
                <%
                    java.util.List<String> userLists = (java.util.List<String>) session.getAttribute("userLists");
                    if (userLists != null && !userLists.isEmpty()) {
                %>
                <ul class="data-list">
                    <% for (int i = 0; i < userLists.size(); i++) { %>
                    <li>
                        <span class="data-index"><%= i + 1 %></span>
                        <span class="data-value"><%= userLists.get(i) %></span>
                    </li>
                    <% } %>
                </ul>
                <% } else { %>
                <div class="empty-data">
                    <i class="far fa-folder-open"></i>
                    <p>暂无数据</p>
                </div>
                <% } %>
            </div>
        </div>

        <!-- 数据卡片 2 - 带统计信息的展示 -->
        <div class="data-card">
            <div class="card-header">
                <h3 class="card-title">好友统计</h3>
            </div>
            <div class="card-body">
                <% if (userLists != null && !userLists.isEmpty()) { %>
                <ul class="data-list">
                    <li>
                        <span class="data-value">数据总数</span>
                        <span class="data-value" style="font-weight: bold; color: #3498db;"><%= userLists.size() %></span>
                    </li>
                    <li>
                        <span class="data-value">首条数据</span>
                        <span class="data-value"><%= userLists.get(0) %></span>
                    </li>
                    <li>
                        <span class="data-value">末条数据</span>
                        <span class="data-value"><%= userLists.get(userLists.size() - 1) %></span>
                    </li>
                </ul>
                <% } else { %>
                <div class="empty-data">
                    <i class="far fa-chart-bar"></i>
                    <p>暂无统计数据</p>
                </div>
                <% } %>
            </div>
        </div>

        <!-- 数据卡片 3 - 搜索过滤功能 -->

    </div>
</div>

<script>
    // 页面加载完成后执行
    document.addEventListener('DOMContentLoaded', function() {
        // 获取列表数据
        const userLists = [];
        <% if (userLists != null && !userLists.isEmpty()) {
            for (String item : userLists) {
        %>
        userLists.push("<%= item.replace("\"", "\\\"") %>");
        <% } } %>

        // 搜索功能实现
        const searchInput = document.getElementById('searchInput');
        const filteredList = document.getElementById('filteredList');

        // 初始化搜索结果
        renderSearchResults(userLists);

        // 搜索输入监听
        searchInput.addEventListener('input', function() {
            const keyword = this.value.toLowerCase();
            const filtered = userLists.filter(item =>
                item.toLowerCase().includes(keyword)
            );
            renderSearchResults(filtered);
        });

        // 渲染搜索结果
        function renderSearchResults(results) {
            filteredList.innerHTML = '';
            if (results.length === 0) {
                const li = document.createElement('li');
                li.className = 'data-value';
                li.style.color = '#757575';
                li.style.textAlign = 'center';
                li.style.padding = '15px 0';
                li.textContent = '未找到匹配结果';
                filteredList.appendChild(li);
            } else {
                results.forEach((item, index) => {
                    const li = document.createElement('li');
                    li.innerHTML = `
                            <span class="data-index">${index + 1}</span>
                            <span class="data-value">${item}</span>
                        `;
                    filteredList.appendChild(li);
                });
            }
        }

        // 添加卡片动画效果
        const cards = document.querySelectorAll('.data-card');
        cards.forEach((card, index) => {
            // 为每个卡片添加延迟动画
            card.style.transitionDelay = `${index * 0.1}s`;

            // 触发动画
            setTimeout(() => {
                card.style.opacity = '1';
                card.style.transform = 'translateY(0)';
            }, 100 + index * 100);
        });
    });
</script>
</body>
</html>